<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8">
        <title>欢迎页面-X-admin2.2</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" th:href="@{/css/font.css}" href="./css/font.css">
        <link rel="stylesheet" th:href="@{/css/xadmin.css}" href="./css/xadmin.css">
        <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>

        <!-- <link rel="stylesheet" href="./css/theme5.css"> -->
        <script th:src="@{/lib/layui/layui.js}" src="./lib/layui/layui.js" charset="utf-8"></script>
        <script th:src="@{/js/xadmin.js}" type="text/javascript" src="./js/xadmin.js"></script>
        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>

        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <form method="post" class="layui-form layui-col-space5" id="searchForm">
                                <div class="layui-inline layui-show-xs-block">
                                    <input type="text" name="stuName"  id="search" placeholder="请输入您查找的学生姓名" autocomplete="off" class="layui-input">
                                    <input type="text" id="isSearch" value="no" hidden>

                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <button type="button" class="layui-btn"  lay-submit="" lay-filter="sreach" onclick="sub()"><i class="layui-icon">&#xe615;</i></button>
                                </div>
                            </form>
                        </div>
                        <div class="layui-card-header">
                            <button class="layui-btn layui-btn-danger" onclick="getScore()" id="refresh"><i class="layui-icon">&#xe669;</i>刷新学生信息</button>
<!--                            <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>-->
                            <button class="layui-btn" onclick="xadmin.open('添加信息','./member-add.html',600,400)"><i class="layui-icon"></i>添加</button>

                            <button type="button" class="layui-btn layui-btn-normal"  onclick="znb()" id="reload" ><i class="layui-icon">&#xe669;</i>执行数据分析</button>

                        </div>
                        <div class="layui-card-body layui-table-body layui-table-main">
                            <table class="layui-table layui-form">
                                <thead>
                                  <tr>
                                    <th>学号</th>
                                    <th>姓名</th>
                                    <th>上课签到次数</th>
                                    <th>平均座位号</th>
                                    <th>签到得分</th>
                                    <th>问答得分</th>
                                      <th>总分</th>
                                    <th>操作</th></tr>
                                </thead>
                                <tbody id="test">
                                  <tr>
                                    <td>
                                      <input type="checkbox" name="id" value="1"   lay-skin="primary"> 
                                    </td>
                                    <td>1</td>
                                    <td>小明</td>
                                    <td>男</td>
                                    <td>13000000000</td>
                                    <td>北京市 海淀区</td>
                                    <td class="td-status">
                                      <span class="layui-btn layui-btn-normal layui-btn-mini">已启用</span></td>
                                    <td class="td-manage">
                                      <a onclick="member_stop(this,'10001')" href="javascript:;"  title="启用">
                                        <i class="layui-icon">&#xe601;</i>
                                      </a>
                                      <a title="编辑"  onclick="xadmin.open('编辑','member-edit.html',600,400)" href="javascript:;">
                                        <i class="layui-icon">&#xe642;</i>
                                      </a>
                                      <a onclick="xadmin.open('修改密码','member-password.html',600,400)" title="修改密码" href="javascript:;">
                                        <i class="layui-icon">&#xe631;</i>
                                      </a>
                                      <a title="删除" onclick="member_del(this,'要删除的id')" href="javascript:;">
                                        <i class="layui-icon">&#xe640;</i>
                                      </a>
                                    </td>
                                  </tr>
                                  <tr>
                                    <td>
                                      <input type="checkbox" name="id"  value="2" lay-skin="primary">
                                    </td>
                                    <td>1</td>
                                    <td>小明</td>
                                    <td>男</td>
                                    <td>13000000000</td>
                                    <td>北京市 海淀区</td>
                                    <td class="td-status">
                                      <span class="layui-btn layui-btn-normal layui-btn-mini">已启用</span></td>
                                    <td class="td-manage">
                                      <a onclick="member_stop(this,'10001')" href="javascript:;"  title="启用">
                                        <i class="layui-icon">&#xe601;</i>
                                      </a>
                                      <a title="编辑"  onclick="xadmin.open('编辑','member-edit.html',600,400)" href="javascript:;">
                                        <i class="layui-icon">&#xe642;</i>
                                      </a>
                                      <a onclick="xadmin.open('修改密码','member-password.html',600,400)" title="修改密码" href="javascript:;">
                                        <i class="layui-icon">&#xe631;</i>
                                      </a>
                                      <a title="删除" onclick="member_del(this,'要删除的id')" href="javascript:;">
                                        <i class="layui-icon">&#xe640;</i>
                                      </a>
                                    </td>
                                  </tr>
                                  <tr>
                                    <td>
                                      <input type="checkbox" name="id" value="3"  lay-skin="primary">
                                    </td>
                                    <td>1</td>
                                    <td>小明</td>
                                    <td>男</td>
                                    <td>13000000000</td>
                                    <td>北京市 海淀区</td>
                                    <td class="td-status">
                                      <span class="layui-btn layui-btn-normal layui-btn-mini">已启用</span></td>
                                    <td class="td-manage">
                                      <a onclick="member_stop(this,'10001')" href="javascript:;"  title="启用">
                                        <i class="layui-icon">&#xe601;</i>
                                      </a>
                                      <a title="编辑"  onclick="xadmin.open('编辑','member-edit.html',600,400)" href="javascript:;">
                                        <i class="layui-icon">&#xe642;</i>
                                      </a>
                                      <a onclick="xadmin.open('修改密码','member-password.html',600,400)" title="修改密码" href="javascript:;">
                                        <i class="layui-icon">&#xe631;</i>
                                      </a>
                                      <a title="删除" onclick="member_del(this,'要删除的id')" href="javascript:;">
                                        <i class="layui-icon">&#xe640;</i>
                                      </a>
                                    </td>
                                  </tr>
                                  <tr>
                                    <td>
                                      <input type="checkbox" name="id" value="4"  lay-skin="primary">
                                    </td>
                                    <td>1</td>
                                    <td>小明</td>
                                    <td>男</td>
                                    <td>13000000000</td>
                                    <td>北京市 海淀区</td>
                                    <td class="td-status">
                                      <span class="layui-btn layui-btn-normal layui-btn-mini">已启用</span></td>
                                    <td class="td-manage">
                                      <a onclick="member_stop(this,'10001')" href="javascript:;"  title="启用">
                                        <i class="layui-icon">&#xe601;</i>
                                      </a>
                                      <a title="编辑"  onclick="xadmin.open('编辑','member-edit.html',600,400)" href="javascript:;">
                                        <i class="layui-icon">&#xe642;</i>
                                      </a>
                                      <a onclick="xadmin.open('修改密码','member-password.html',600,400)" title="修改密码" href="javascript:;">
                                        <i class="layui-icon">&#xe631;</i>
                                      </a>
                                      <a title="删除" onclick="member_del(this,'要删除的id')" href="javascript:;">
                                        <i class="layui-icon">&#xe640;</i>
                                      </a>
                                    </td>
                                  </tr>
                                  <tr>
                                    <td>
                                      <input type="checkbox" name="id" value="5"  lay-skin="primary">
                                    </td>
                                    <td>1</td>
                                    <td>小明</td>
                                    <td>男</td>
                                    <td>13000000000</td>
                                    <td>北京市 海淀区</td>
                                    <td class="td-status">
                                      <span class="layui-btn layui-btn-normal layui-btn-mini">已启用</span></td>
                                    <td class="td-manage">
                                      <a onclick="member_stop(this,'10001')" href="javascript:;"  title="启用">
                                        <i class="layui-icon">&#xe601;</i>
                                      </a>
                                      <a title="编辑"  onclick="xadmin.open('编辑','member-edit.html',600,400)" href="javascript:;">
                                        <i class="layui-icon">&#xe642;</i>
                                      </a>
                                      <a onclick="xadmin.open('修改密码','member-password.html',600,400)" title="修改密码" href="javascript:;">
                                        <i class="layui-icon">&#xe631;</i>
                                      </a>
                                      <a title="删除" onclick="member_del(this,'要删除的id')" href="javascript:;">
                                        <i class="layui-icon">&#xe640;</i>
                                      </a>
                                    </td>
                                  </tr>
                                  <tr>
                                    <td>
                                     <input type="checkbox" name="id" value="6" lay-skin="primary">
                                    </td>
                                    <td>1</td>
                                    <td>小明</td>
                                    <td>男</td>
                                    <td>13000000000</td>
                                    <td>北京市 海淀区</td>
                                    <td class="td-status">
                                      <span class="layui-btn layui-btn-normal layui-btn-mini">已启用</span></td>
                                    <td class="td-manage">
                                      <a onclick="member_stop(this,'10001')" href="javascript:;"  title="启用">
                                        <i class="layui-icon">&#xe601;</i>
                                      </a>
                                      <a title="编辑"  onclick="xadmin.open('编辑','member-edit.html',600,400)" href="javascript:;">
                                        <i class="layui-icon">&#xe642;</i>
                                      </a>
                                      <a onclick="xadmin.open('修改密码','member-password.html',600,400)" title="修改密码" href="javascript:;">
                                        <i class="layui-icon">&#xe631;</i>
                                      </a>
                                      <a title="删除" onclick="member_del(this,'要删除的id')" href="javascript:;">
                                        <i class="layui-icon">&#xe640;</i>
                                      </a>
                                    </td>
                                  </tr>
                                </tbody>
                            </table>
                        </div>
                        <div class="layui-card-body ">
                            <div class="page">
                                <div>
                                    <a class="prev" id="previousPages" onclick="changePages(this)">上一页</a>
                                    <span class="current" id="nowPages">1</span>
                                    <a class="next" onclick="changePages(this)" id="NextPages">下一页</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div> 
    </body>
    <script>
      layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var  form = layui.form;


        // 监听全选
        form.on('checkbox(checkall)', function(data){

          if(data.elem.checked){
            $('tbody input').prop('checked',true);
          }else{
            $('tbody input').prop('checked',false);
          }
          form.render('checkbox');
        }); 
        
        //执行一个laydate实例
        laydate.render({
          elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
          elem: '#end' //指定元素
        });


      });

       /*用户-停用*/
      function member_stop(obj,id){
          layer.confirm('确认要停用吗？',function(index){

              if($(obj).attr('title')=='启用'){

                //发异步把用户状态进行更改
                $(obj).attr('title','停用');
                $(obj).find('i').html('&#xe62f;');

                $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用');
                layer.msg('已停用!',{icon: 5,time:1000});

              }else{
                $(obj).attr('title','启用')
                $(obj).find('i').html('&#xe601;');

                $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已启用');
                layer.msg('已启用!',{icon: 5,time:1000});
              }
              
          });
      }



      /*用户-删除*/
      function member_del(obj,id){

           var stuNum = obj.parentNode.parentNode.id;

          layer.confirm('确认要删除吗？',function(index){
              //发异步删除数据
              $.ajax({
                  //几个参数需要注意一下
                  type: "POST",//方法类型
                  dataType: "text",//预期服务器返回的数据类型
                  url: "/stu/delete" ,//url


                  async:false,
                  data: {
                      stuNum : stuNum
                  },
                  success : function (json) {
                      // alert("正确");
                      if(json==1){
                          // console.log("可以！");
                          layer.msg('已删除!',{icon:1,time:1000});
                          return false;
                      }
                      else {
                          layer.alert("删除异常", {
                              icon: 5
                          })
                      }
                  },
                  error : function(json) {
                      layer.alert("删除异常", {
                          icon: 5
                      });                        }
              });

              $(obj).parents("tr").remove();
          });
      }



      function delAll (argument) {
        var ids = [];

        // 获取选中的id 
        $('tbody input').each(function(index, el) {
            if($(this).prop('checked')){
               ids.push($(this).val())
            }
        });
  
        layer.confirm('确认要删除吗？'+ids.toString(),function(index){
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
            $(".layui-form-checked").not('.header').parents('tr').remove();
        });
      }
    </script>
<script>
    window.onload= function (){
        getScore();
    };
    
    
    function sub() {
        $.ajax({
            //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: "/infos/shows" ,//url
            data: $('#searchForm').serialize(),
            success : function (json) {
                // alert("jj");
                let li = json;
                let data = li.records;
                var str1 = "";
                // console.log(JSON.stringify(json));
                // console.log(document.getElementById("test2").innerHTML);
                document.getElementById("test").innerHTML = "";
                document.getElementById("isSearch").value = "yes";
                document.getElementById("nowPages").innerText = "1";
                console.log(li);
                displayPages(li);
                for (var i = 0; i < data.length; i++) {

                    let signscore = data[i].signUpScore.toFixed(2);
                    let askScore = data[i].askScore.toFixed(2);
                    let total = data[i].totalScore.toFixed(2);
                    str1 += "<tr id="+data[i].stuNum+">\n" +
                        "<td>"+data[i].stuNum+"</td>\n"
                        +"<td>"+data[i].stuName+"</td>\n"
                        +"<td>"+data[i].signupTimes+"</td>\n"
                        +"<td>"+data[i].avgSeatNum.toFixed(2)+"</td>\n"+
                        "<td>"+signscore+"</td>\n"
                        +"<td>"+askScore+"</td>\n"
                        +  "<td>"+total+"</td>\n"+

                        "<td class=\"td-manage\">\n" +
                        "             <a title=\"编辑\"  onclick=\"member_edit(this)\" href=\"javascript:;\">\n" +
                        "                <i class=\"layui-icon\">&#xe642;</i>\n" +
                        "             </a>\n" +
                        "             <a title=\"删除\" onclick=\"member_del(this,'要删除的id')\" href=\"javascript:;\">\n" +
                        "                  <i class=\"layui-icon\">&#xe640;</i>\n" +
                        "             </a>\n" +
                        "                           </td>"+
                        "</tr>";
                    console.log()

                }
                document.getElementById("test").innerHTML += str1;
            },
            error : function() {
                alert("异常！");
            }
        });
    }

    function getScore(){
        $.ajax(
            {
                type: "POST",
                url : "/infos/shows",
                data:{
                    "stuName" : ""
                },
                dataType: "json",
                success : function (json){
                    let IPage = json;
                    var str1 ="";
                    console.log(json);
                    let data = IPage.records;
                    console.log(data);
                    document.getElementById("test").innerHTML = "";

                    document.getElementById("nowPages").innerText = "1";
                    document.getElementById("previousPages").style.visibility="hidden";
                    document.getElementById("NextPages").style.visibility="visible";
                    document.getElementById("isSearch").value="no";
                    for(var i =0;i<data.length;i++){

                        let signscore = data[i].signUpScore.toFixed(2);
                        let askScore = data[i].askScore.toFixed(2);
                        let total = data[i].totalScore.toFixed(2);
                        str1 += "<tr id="+data[i].stuNum+">\n" +
                            "<td>"+data[i].stuNum+"</td>\n"
                            +"<td>"+data[i].stuName+"</td>\n"
                            +"<td>"+data[i].signupTimes+"</td>\n"
                            +"<td>"+data[i].avgSeatNum.toFixed(2)+"</td>\n"+
                            "<td>"+signscore+"</td>\n"
                            +"<td>"+askScore+"</td>\n"
                            +  "<td>"+total+"</td>\n"+

                            "<td class=\"td-manage\">\n" +
                            "             <a title=\"编辑\"  onclick=\"member_edit(this)\" href=\"javascript:;\">\n" +
                            "                <i class=\"layui-icon\">&#xe642;</i>\n" +
                            "             </a>\n" +
                            "             <a title=\"删除\" onclick=\"member_del(this,'要删除的id')\" href=\"javascript:;\">\n" +
                            "                  <i class=\"layui-icon\">&#xe640;</i>\n" +
                            "             </a>\n" +
                            "                           </td>"+
                        "</tr>";
                        console.log()

                    }
                    $("#test").append(str1);

                    // document.getElementById("test").innerHTML = str1;
                }
            }
        )
    }

    function displayPages(data){
        console.log("current "+data.current);
        console.log("pages "+data.pages);

        if(data.current!==1){
            document.getElementById("previousPages").style.visibility="visible";
        }
        else {
            document.getElementById("previousPages").style.visibility="hidden";

        }
        if(data.current!==data.pages){
            document.getElementById("NextPages").style.visibility="visible";
        }
        else {
            document.getElementById("NextPages").style.visibility="hidden";
        }

        if(data.pages==0){
            document.getElementById("previousPages").style.visibility="hidden";

            document.getElementById("NextPages").style.visibility="hidden";

        }
    }


    function changePages(obj){
        // console.log(obj.id);
        var action = obj.id;
        var nowPages =Number(document.getElementById("nowPages").innerText);
        // console.log("nowPages  "+nowPages);
        var stuName =   document.getElementById("search").value;
        let isSearch = document.getElementById("isSearch").value;
        console.log(isSearch);
        if(isSearch==='no'||isSearch==='false'){
            username = "";
        }
        if(action === 'NextPages') {
            $.ajax(
                {
                    type: "POST",

                    url: "/infos/shows/" + (nowPages + 1),
                    data: {
                        "stuName": stuName
                    },
                    dataType: "json",
                    success: function (json) {

                        console.log(json.records)
                        let li = json;
                        var str1 = "";
                        // alert(data.content);
                        document.getElementById("test").innerHTML = "";

                        displayPages(li);


                        let data = li.records;



                        for(var i =0;i<data.length;i++){
                            let signscore = data[i].signUpScore.toFixed(2);
                            let askScore = data[i].askScore.toFixed(2);
                            let total = data[i].totalScore.toFixed(2);
                            str1 += "<tr id="+data[i].stuNum+">\n" +
                                "<td>"+data[i].stuNum+"</td>\n"
                                +"<td>"+data[i].stuName+"</td>\n"
                                +"<td>"+data[i].signupTimes+"</td>\n"
                                +"<td>"+data[i].avgSeatNum.toFixed(2)+"</td>\n"+
                                "<td>"+signscore+"</td>\n"
                                +"<td>"+askScore+"</td>\n"
                                +  "<td>"+total+"</td>\n"+

                                "<td class=\"td-manage\">\n" +
                                "             <a title=\"编辑\"  onclick=\"member_edit(this)\" href=\"javascript:;\">\n" +
                                "                <i class=\"layui-icon\">&#xe642;</i>\n" +
                                "             </a>\n" +
                                "             <a title=\"删除\" onclick=\"member_del(this,'要删除的id')\" href=\"javascript:;\">\n" +
                                "                  <i class=\"layui-icon\">&#xe640;</i>\n" +
                                "             </a>\n" +
                                "                           </td>"+
                                "</tr>";
                            console.log()

                        }
                        let text =  document.getElementById("nowPages").innerText;
                        text++;
                        document.getElementById("nowPages").innerText = text;
                        console.log("newPages  "+document.getElementById("nowPages").innerText);
                        displayPages(li);
                        $("#test").append(str1);

                    }
                }
            )
        }
        if(action ==='previousPages') {
            $.ajax(
                {
                    type: "POST",

                    url: "/infos/shows/" + (nowPages - 1),
                    data: {
                        "stuName": stuName
                    },
                    dataType: "json",
                    success: function (json) {
                        console.log(nowPages);

                        // alert("jj0");
                        let li = json;
                        var str1 = "";
                        // ;

                        document.getElementById("test").innerHTML = "";

                        displayPages(li);

                        let data = li.records;

                        displayPages(li);


                        console.log(data);

                        for (var i = 0; i < data.length; i++) {
                            let signscore = data[i].signUpScore.toFixed(2);
                            let askScore = data[i].askScore.toFixed(2);
                            let total = data[i].totalScore.toFixed(2);
                            str1 += "<tr id="+data[i].stuNum+">\n" +
                                "<td>"+data[i].stuNum+"</td>\n"
                                +"<td>"+data[i].stuName+"</td>\n"
                                +"<td>"+data[i].signupTimes+"</td>\n"
                                +"<td>"+data[i].avgSeatNum.toFixed(2)+"</td>\n"+
                                "<td>"+signscore+"</td>\n"
                                +"<td>"+askScore+"</td>\n"
                                +  "<td>"+total+"</td>\n"+

                                "<td class=\"td-manage\">\n" +
                                "             <a title=\"编辑\"  onclick=\"member_edit(this)\" href=\"javascript:;\">\n" +
                                "                <i class=\"layui-icon\">&#xe642;</i>\n" +
                                "             </a>\n" +
                                "             <a title=\"删除\" onclick=\"member_del(this,'要删除的id')\" href=\"javascript:;\">\n" +
                                "                  <i class=\"layui-icon\">&#xe640;</i>\n" +
                                "             </a>\n" +
                                "                           </td>"+
                                "</tr>";
                            console.log()

                        }
                        let text =  document.getElementById("nowPages").innerText;
                        text--;
                        document.getElementById("nowPages").innerText = text;
                        console.log("newPages  "+document.getElementById("nowPages").innerText);


                        $("#test").append(str1);

                    }
                }
            )
        }

    }


    function znb(){
        console.log("znb");
        // alert("nb!");
        layer.alert("正在执行哟！一分钟之后刷新一下就好啦！", {
            icon: 6
        });
        $.ajax(
            {
                type: "GET",

                url: "/info/reload",

                dataType: "text",
            }
        )
    }

    function member_edit(obj) {
        var num = obj.parentNode.parentNode.id;

        xadmin.open('编辑','member-edit.html?'+num,600,400);
    }
</script>
</html>